package cn.icyzx.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import cn.icyzx.service.LoginService;
import cn.icyzx.service.UserService;

import javax.servlet.http.HttpSession;

/**
 * Created by 郑凯 on 2016/8/22.
 */
@Controller
public class UserProcess {


    @Autowired
    public LoginService loginService;

    @Autowired
    UserService userService;


    /**
     * 注销用户并转发到主页
     * user off
     */
    @RequestMapping("/off")
    String off(HttpSession httpSession) {
        httpSession.invalidate();
        return "redirect:/";
    }

    @RequestMapping(value = "/personal", method = RequestMethod.GET)
    public ModelAndView personal(HttpSession session, ModelAndView modelAndView) {
        if (session.getAttribute("user") == null) {
            modelAndView = new ModelAndView("redirect:/login");
            modelAndView.addObject("loginTip", "请先登录");
            return modelAndView;
        } else {
            modelAndView = new ModelAndView("set-personal");
            return modelAndView;
        }
    }


}
